package com.yz.platform.modules.sys.controller;

import com.yz.platform.common.utils.PageUtils;
import com.yz.platform.common.utils.Query;
import com.yz.platform.common.utils.R;
import com.yz.platform.modules.sys.entity.SysUserGroupEntity;
import com.yz.platform.modules.sys.service.SysUserGroupService;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;





/**
 * 
 * 
 * @author lin
 * @email 
 * @date 2017-10-20 22:32:20
 */
@RestController
@RequestMapping("sysusergroup")
public class SysUserGroupController {
	@Autowired
	private SysUserGroupService sysUserGroupService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("sysusergroup:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

		List<SysUserGroupEntity> sysUserGroupList = sysUserGroupService.queryList(query);
		int total = sysUserGroupService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(sysUserGroupList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{groupId}")
	@RequiresPermissions("sysusergroup:info")
	public R info(@PathVariable("groupId") Integer groupId){
		SysUserGroupEntity sysUserGroup = sysUserGroupService.queryObject(groupId);
		
		return R.ok().put("sysUserGroup", sysUserGroup);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("sysusergroup:save")
	public R save(@RequestBody SysUserGroupEntity sysUserGroup){
		sysUserGroupService.save(sysUserGroup);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("sysusergroup:update")
	public R update(@RequestBody SysUserGroupEntity sysUserGroup){
		sysUserGroupService.update(sysUserGroup);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("sysusergroup:delete")
	public R delete(@RequestBody Integer[] groupIds){
		sysUserGroupService.deleteBatch(groupIds);
		
		return R.ok();
	}
	
}
